package com.scsj.supermarket.view.activity.submitmodel;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.scsj.supermarket.R;
import com.scsj.supermarket.adapter.MineOrderDetailAdapter;
import com.scsj.supermarket.adapter.SubmitOrderAdapter;
import com.scsj.supermarket.bean.TotalOrderBean;
import com.scsj.supermarket.utils.SkipUtils;
import com.scsj.supermarket.utils.Tool;
import com.scsj.supermarket.view.activity.baseactivitymodel.BaseActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * 提交订单页面
 */
public class SubmitOrderActivity extends BaseActivity implements View.OnClickListener{

    private RecyclerView order_detail_rv;
    private List<TotalOrderBean> totalOrderBeans;
    private SubmitOrderAdapter submitOrderAdapter;
    private RelativeLayout seeMoreItemRl, submitOrderLayout;
    private boolean isShowAllItem = false;
    private List twoList;
    private EditText otherInfoEt;
    private ScrollView scrollView;
    private TextView totalGoodsNum, orderDetailState, orderDetailStateDescription, orderDetailTopBtn, orderDetailLeftBtn, orderDetailRightBtn;
    private int orderStateNumber;
    private TextView submitOrderBtn;

    @Override
    protected void createView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_submit_order);

        orderStateNumber = getIntent().getIntExtra("order_state", -1);
        initToolbar();
        setToolbarTitle("订单详情");
        hasBack(true);
        initView();
        initData();
        initListener();

    }

    @Override
    protected void initView() {

        order_detail_rv = findViewById(R.id.order_detail_rv);
        order_detail_rv.setLayoutManager(new LinearLayoutManager(this));
        order_detail_rv.setNestedScrollingEnabled(false);
        seeMoreItemRl= findViewById(R.id.order_detail_totle_num_rl);
        submitOrderLayout= findViewById(R.id.submit_order_layout);
        otherInfoEt= findViewById(R.id.order_other_info);
        scrollView= findViewById(R.id.scroll_view);
        submitOrderBtn= findViewById(R.id.submit_order_btn_tv);
        seeMoreItemRl = findViewById(R.id.order_detail_totle_num_rl);
        submitOrderLayout = findViewById(R.id.submit_order_layout);
        otherInfoEt = findViewById(R.id.order_other_info);
        scrollView = findViewById(R.id.scroll_view);

        otherInfoEt.setOnFocusChangeListener(new android.view.View.
                OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    // 此处为得到焦点时的处理内容
                    // Tool.controlKeyboardLayout(scrollView,SubmitOrderActivity.this);

                    scrollView.scrollTo(0, 1000);
                } else {
                    // 此处为失去焦点时的处理内容
                }
            }
        });
        //toSelectPage(orderStateNumber);
    }

    @Override
    protected void initListener() {
        seeMoreItemRl.setOnClickListener(this);
        submitOrderBtn.setOnClickListener(this);
    }

    @Override
    protected void initData() {
        totalOrderBeans = new ArrayList<>();

        List<Integer> data = new ArrayList<>();
        data.add(R.mipmap.ic_launcher);
        data.add(R.mipmap.ic_launcher);
        data.add(R.mipmap.ic_launcher);
        data.add(R.mipmap.ic_launcher);

        twoList = new ArrayList();
        twoList.add(totalOrderBeans.get(0));
        twoList.add(totalOrderBeans.get(1));
        submitOrderAdapter = new SubmitOrderAdapter(twoList, this);
        order_detail_rv.setAdapter(submitOrderAdapter);

    }

    private void toSelectPage(int orderStateNumber) {

        switch (orderStateNumber) {

            case 0:
                //待付款

                break;
            case 1:
                //待发货

                break;
        }
    }

    @Override
    public void onClick(View view) {

        switch (view.getId()) {
            case R.id.order_detail_totle_num_rl:
                if (!isShowAllItem) {
                    //加载所有条目
                    submitOrderAdapter = new SubmitOrderAdapter(totalOrderBeans, this);
                    isShowAllItem = true;
                } else {
                    //加载前两项
                    submitOrderAdapter = new SubmitOrderAdapter(twoList, this);
                    isShowAllItem = false;
                }
                order_detail_rv.setAdapter(submitOrderAdapter);
                break;
            case R.id.order_other_info:
                Tool.controlKeyboardLayout(scrollView, this);
                break;
            case R.id.submit_order_btn_tv:
                SkipUtils.toOrderPayPage(this);
                break;
        }
    }
}
